package cn.sxt.yxl.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.sxt.util.PageInfoUtil;
import cn.sxt.yxl.dao.IAAdminsDao;
import cn.sxt.yxl.dao.IAAnswerDao;
import cn.sxt.yxl.dao.IAColumnsDao;
import cn.sxt.yxl.dao.IAItemsDao;
import cn.sxt.yxl.dao.IAQuestionDao;
import cn.sxt.yxl.dao.IARoleDao;
import cn.sxt.yxl.pojo.AAdmins;
import cn.sxt.yxl.pojo.AAnswer;
import cn.sxt.yxl.pojo.AColumns;
import cn.sxt.yxl.pojo.AItems;
import cn.sxt.yxl.pojo.AQuestion;
import cn.sxt.yxl.pojo.ARole;
import cn.sxt.yxl.service.IUsersService;



/**
 * 鐢ㄦ埛Service瀹炵幇绫�
 * @author wangshSxt
 *
 */
@Service("usersService")
public class UsersServiceImpl implements IUsersService
{
	/* ??? IAAdminsDao濡備綍璧嬪�� */
	@Resource
	private IAAdminsDao adminsDao;
	@Resource
	private IARoleDao roleDao;
	@Resource
	private IAColumnsDao columnsDao;
	@Resource
	private IAItemsDao itemsDao;
	@Resource
	private IAQuestionDao questionDao;
	@Resource
	private IAAnswerDao answerDao;

	@Override
	public AAdmins findOneAdminsService(Map<String, Object> condMap)
	{
		return this.adminsDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/* 淇濆瓨璁板綍 */
		int res = this.adminsDao.saveOne(admins);
		
		/*String str = null ; 
		str.toString() ; */
		
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/* 淇濆瓨璁板綍 */
		int res = this.adminsDao.updateOne(admins);
		
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject deleteOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/* 淇濆瓨璁板綍 */
		int res = this.adminsDao.deleteOne(admins);
		
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public List<AAdmins> findCondListAdminsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		if(pageInfoUtil != null)
		{
			/* 鍒嗛〉 */
			/* 鏌ヨ鎬昏褰曟暟 */
			Page<AAdmins> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 鏌ヨ鏁版嵁 */
			List<AAdmins> adminsList = this.adminsDao.findCondList(condMap);
			/* 璁剧疆鎬昏褰曟暟 ,涓�瀹氳鍦ㄦ煡璇㈢粨鏋滀箣鍚�*/
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			return adminsList;
		}
		return this.adminsDao.findCondList(condMap);
	}
	
	@Override
	public ARole findOneRoleService(Map<String, Object> condMap)
	{
		return this.roleDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneRoleService(ARole role)
	{
		JSONObject resultJSON = new JSONObject();
		/* 淇濆瓨璁板綍 */
		int res = this.roleDao.saveOne(role);
		
		/*String str = null ; 
		str.toString() ; */
		
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", role.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneRoleService(ARole role)
	{
		JSONObject resultJSON = new JSONObject();
		/* 淇濆瓨璁板綍 */
		int res = this.roleDao.updateOne(role);
		
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", role.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject deleteOneRoleService(ARole role)
	{
		JSONObject resultJSON = new JSONObject();
		/* 淇濆瓨璁板綍 */
		int res = this.roleDao.deleteOne(role);
		
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", role.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public List<ARole> findCondListRoleService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		if(pageInfoUtil != null)
		{
			/* 鍒嗛〉 */
			/* 鏌ヨ鎬昏褰曟暟 */
			Page<ARole> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 鏌ヨ鏁版嵁 */
			List<ARole> roleList = this.roleDao.findCondList(condMap);
			/* 璁剧疆鎬昏褰曟暟 ,涓�瀹氳鍦ㄦ煡璇㈢粨鏋滀箣鍚�*/
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			return roleList;
		}
		return this.roleDao.findCondList(condMap);
	}

	@Override
	public AColumns findOneColumnsService(Map<String, Object> condMap) {
		return this.columnsDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneColumnsService(AColumns columns) {
		int res = this.columnsDao.saveOne(columns);
		JSONObject resultJSON = new JSONObject();
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneColumnsService(AColumns columns) {
		int res = this.columnsDao.updateOne(columns);
		JSONObject resultJSON = new JSONObject();
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject deleteOneColumnsService(AColumns columns) {
		int res = this.columnsDao.deleteOne(columns);
		JSONObject resultJSON = new JSONObject();
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public List<AColumns> findCondListColumnsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		if(pageInfoUtil != null){
			Page<AColumns> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(),pageInfoUtil.getPageSize());
			List<AColumns> list = this.columnsDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return list;
		}
		return this.columnsDao.findCondList(condMap);
	}

	@Override
	public AItems findOneItemsService(Map<String, Object> condMap) {
		return this.itemsDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneItemsService(AItems items) {
		int res = this.itemsDao.saveOne(items);
		JSONObject resultJSON = new JSONObject();
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", items.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneItemsService(AItems items) {
		int res = this.itemsDao.updateOne(items);
		JSONObject resultJSON = new JSONObject();
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", items.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public JSONObject deleteOneItemsService(AItems items) {
		int res = this.itemsDao.deleteOne(items);
		JSONObject resultJSON = new JSONObject();
		if(res > 0 )
		{
			/* 瀛樺偍缁撴灉 */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", items.getId() + "");
			dataJSON.put("effectCount", res);
			
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", "鎴愬姛");
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", "澶辫触");
		}
		return resultJSON;
	}

	@Override
	public List<AItems> findCondListItemsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		if(pageInfoUtil != null){
			Page<AItems> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			System.out.println("---------------------------"+page);
			List<AItems> list = this.itemsDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			System.out.println(pageInfoUtil.getTotalPage()+"***********************************************************************************");
			return list;
		}
		return this.itemsDao.findCondList(condMap);
	}

	@Override
	public AQuestion findOneQuestionService(Map<String, Object> condMap) {
		return this.questionDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneQuestionService(AQuestion question) {
		return null;
	}

	@Override
	public JSONObject updateOneQuestionService(AQuestion question) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public JSONObject deleteOneQuestionService(AQuestion question) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<AQuestion> findCondListQuestionService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public AAnswer findOneAnswerService(Map<String, Object> condMap) {
		return this.answerDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneAnswerService(AAnswer answer) {
		return null;
	}

	@Override
	public JSONObject updateOneAnswerService(AAnswer answer) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public JSONObject deleteOneAnswerService(AAnswer answer) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<AAnswer> findCondListAnswerService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		// TODO Auto-generated method stub
		return null;
	}
}
